set more off


************************************************************************************************************
**************************************************Figure S.6************************************************
************************************************************************************************************


use flexlogit,clear
set seed 100
preserve
egen tag = tag(ID)
keep if tag == 1 // keep one row per cluster
keep ID
gen cluster_index = _n // index clusters for easy lookup later
tempfile clusters
save `clusters'
restore
clear
set obs 1000000
gen cluster_index = ceil(runiform() * 54648) // draws random cluster indices
merge m:1 cluster_index using `clusters', keep(match) nogen
gen csID=_n
expand 10,gen(rep)
drop cluster_index rep 
bys csID:gen altID=_n 
sort csID altID

tempfile bootclusters
save `bootclusters'

use flexlogit, clear
merge 1:m ID altID using `bootclusters', keep(match) nogen
drop ID 
rename csID ID 
unique ID
sort ID altID 
save realxz,replace
*/ 


local alpha1 = -0.0177771
local alpha2 = 0.4763404
local alpha3 = 0.4063466
local alpha4 = 0.1372998
local alpha5 = -0.0474275
local alpha6 = 1.167067
local alpha7 = 0.9603329
local alpha8 = 0.7578638
local alpha9 = 0.703609
local alpha10 = 0.5093425
local alpha11 = 0.4026366
local alpha12 = 0.2591573
local alpha13 = 0.1863353
local alpha14 = 0.0471247
local beta=0.5304819



local N = 1000000

*DGP index
*1 == Weitzman
*2 == Satisficing
*3 == Search all goods above a threshold
*4 == Random search


local sigmalist = "0 0.01 0.05 0.1 0.25 0.33 0.5 0.75 0.9 1"

local dgplist = " 1 2 3 4"

local J = 10

local loopcount==0


foreach sigma of local sigmalist {
foreach dgp of local dgplist {

local loopcount = `loopcount'+1
display "LOOP START!"
display "LOOP START!"
display "LOOP START!"
display "LOOP START!"
display "dgp is `dgp'"
display "sigma is `sigma'"


set seed 600`r'

do programs/calibrate.do `alpha1' `alpha2' `alpha3' `alpha4'  `alpha5' `alpha6' `alpha7' `alpha8' `alpha9' `alpha10' `alpha11' `alpha12' `alpha13' `alpha14' `beta' `sigma' `J'  `N' `dgp' 


if(`loopcount' > 1) append using full.dta

save full.dta, replace
}

}



use full,clear 
scatter alpha sigma, yline(-0.0177771) yscale(r(-0.015,-0.018))ylabel(-0.015 -0.016 -0.017 -0.018 -0.019 -0.02, grid) xlabel(0 0.2 0.4 0.6 0.8 1, grid) xtitle("Sigma") ytitle("Alpha Estimates")
graph export zfull.png,replace 
scatter alpha sigma if dgp==1, yline(-0.0177771) yscale(r(-0.015,-0.018))ylabel(-0.015 -0.016 -0.017 -0.018 -0.019 -0.02, grid) xlabel(0 0.2 0.4 0.6 0.8 1, grid) xtitle("Sigma") ytitle("Alpha Estimates")
graph export zdgp1.png ,replace 
scatter alpha sigma if dgp==2, yline(-0.0177771) yscale(r(-0.015,-0.018))ylabel(-0.015 -0.016 -0.017 -0.018 -0.019 -0.02, grid) xlabel(0 0.2 0.4 0.6 0.8 1, grid) xtitle("Sigma") ytitle("Alpha Estimates")
graph export zdgp2.png ,replace 
scatter alpha sigma if dgp==3, yline(-0.0177771) yscale(r(-0.015,-0.018))ylabel(-0.015 -0.016 -0.017 -0.018 -0.019 -0.02, grid) xlabel(0 0.2 0.4 0.6 0.8 1, grid) xtitle("Sigma") ytitle("Alpha Estimates")
graph export zdgp3.png ,replace 
scatter alpha sigma if dgp==4, yline(-0.0177771) yscale(r(-0.015,-0.018))ylabel(-0.015 -0.016 -0.017 -0.018 -0.019 -0.02, grid) xlabel(0 0.2 0.4 0.6 0.8 1, grid) xtitle("Sigma") ytitle("Alpha Estimates")
graph export zdgp4.png ,replace 


